package im.composer.audio.outputstream;

import java.io.IOException;
import java.io.OutputStream;

import javax.sound.sampled.AudioFileFormat.Type;

import org.tritonus.share.sampled.file.AudioOutputStream;

import im.composer.media.audio.stream.LameOutputStream;

public class LameBuilder extends AbstractAudioBuilder {

	public static final Type TYPE = new Type("lame", "mp3");

	@Override
	public Type getType() {
		return TYPE;
	}

	@Override
	public AudioOutputStream build() {
		OutputStream out = new OutputStream() {

			@Override
			public void close() throws IOException {
				dataOutputStream.close();
			}

			@Override
			public void write(int b) throws IOException {
				dataOutputStream.write(b);
			}

			@Override
			public void write(byte[] b) throws IOException {
				dataOutputStream.write(b);
			}

			@Override
			public void write(byte[] b, int off, int len) throws IOException {
				dataOutputStream.write(b, off, len);
			}
		};
		LameOutputStream los = new LameOutputStream(out);
		los.setSourceFormat(audioFormat);
		return los;
	}

}
